jsx3.Class.defineClass(
    "ux.cdb.admin.util.FormatHelper",
    null,null,
    function(helper) {
        helper.UNITS = [];

        helper.getUnitName = function(code) {
            return helper.UNITS[code] || ux.megatron.Main.getServer().getDynamicProperty("@cdb@Unit " + code);
        };

        helper.FormatAmount = function(amount) {
            if(amount) {
                return (new jsx3.util.NumberFormat("#00.00")).format(amount) + helper.getUnitName("Yuan");
            } else {
                return "";
            }
        };

        helper.FormatPeriod = function(period) {
            return (period !=="") ? period + helper.getUnitName("Year") : "";
        };

        helper.FormatPercent = function(percent) {
            return (percent !=="") ? percent + helper.getUnitName("Percent") : "";
        };

        helper.FormatParametersOfExpiryDate = function(s) {
			if(s && s.indexOf('_') > -1){
				var _s = s.split('_');
	            return _s[0] + helper.getUnitName("Month") + _s[1] + helper.getUnitName("Day");
			}
			return s;
        };
		
        helper.FormatParametersOfExpiryPeriod = function(period) {
            return (period !=="" && !isNaN(period)) ? period + helper.getUnitName("PerMonth") : "";
        };
		
		helper.FormatApplyYear = function(year) {
			jsx3.log("FormatApplyYear year: "+ year);
			var result = "";
			try{
				if(year != null && year!="" && year.length==8){
					var year1 = year.substring(0,4);
					var year2 = year.substring(4,8);
					var yearCh = ux.megatron.Main.getServer().getDynamicProperty("@cdb@UnitStudyYear");
					result = year1+"-"+year2+yearCh;
				}
			}catch(e){
				jsx3.log("FormatApplyYear error: "+ e.message);
			}
			return result;
		}

        helper.FormatDate = function(s, format) {
            try {
                if (s === "") return s;
                var dateFormatter = new jsx3.util.DateFormat(format);
                return dateFormatter.format(s);                
            }
            catch (e) {
                ux.cdb.admin.Log.warn("Error in cdb FormatDate", e);
                return s;
            }
        };

        helper.MatrixFormatDate = function(format) {
            return function(element, cdfkey, matrix, column, rownumber, server) {
                var node = matrix.getRecordNode(cdfkey);     
                var val = node.getAttribute(column.getPath());         
                if(val) {         
                    try {
                        var dateFormatter = new jsx3.util.DateFormat(format);
                        element.innerHTML = dateFormatter.format(val);         
                    }
                    catch (e) {
                        ux.cdb.admin.Log.warn("Error in cdb FormatDate", e);
                        element.innerHTML = val;
                    }              
                } else {             
                    element.innerHTML = "";
                }
            };
        };

        helper.MatrixFormatAmount = function(element, cdfkey, matrix, column, rownumber, server) {
            
            var node = matrix.getRecordNode(cdfkey);     
            var val = node.getAttribute(column.getPath());         
            if(val) {             
                var html = (new jsx3.util.NumberFormat("#00.00")).format(val);    
                html = "<span style='float:right'>" + html + "</span>";
                element.innerHTML = html;  
            } else {             
                element.innerHTML = "";
            }
        };
        
        helper.MatrixFormatPercent=function(element, cdfkey, matrix, column, rownumber, server) {           
            var node = matrix.getRecordNode(cdfkey);     
            var val = node.getAttribute(column.getPath());         
            if(val) {                        
                element.innerHTML ="<span style='float:right' align='right'>"+ val + "%</span>";
            }
        };
    }
);
